var maximalSquare = function(matrix) {
  //dp[i][j]表示最大正方形面积
  // 如果dp[i][j+1] dp[i+1][j] dp[i+1][j+1]都等于一，则让dp[i][j]+1
  // 
  let l = matrix.length
  let k = matrix[0].length
  let dp = Array(l).fill(0).map(()=>Array(k).fill(0))
  let length = 0
  for(var i=0;i<matrix.length;i++) {
      for(var j = 0;j<matrix[0].length;j++) {
        if(matrix[i][j]==1) {
          if(i==0||j==0) {
            dp[i][j] = 1
          }else {
            //如果有一个为0，就取值为0，只有全部为1才会加1
            dp[i][j] = Math.min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])+1
          }
        }else {
          dp[i][j] = 0
        }
        length  = Math.max(length,dp[i][j])
      }
  }    
  return length*length
};
console.log(maximalSquare([["1","1","1","1","1"],["1","1","1","1","1"],["1","1","1","1","1"],["1","1","1","1","1"]]))